//
//  Setting_ViewController.m
//  International_Hospital
//
//  Created by LiYiLin on 16/7/4.
//  Copyright © 2016年 LiYiLin. All rights reserved.
//

#import "Setting_ViewController.h"
#import "FeedBackVC.h"

#import "JASidePanelController.h"
#import "Left_ViewController.h"
#import "Login_ViewController.h"
#import "ResetPasswordController.h"

#import <SVProgressHUD.h>

@interface Setting_ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *tableview;
@property (nonatomic,strong) NSArray *strArr;
@property (nonatomic, strong) JASidePanelController * JASide_ViewController;

//记录是否登录的布尔值
@property (nonatomic,assign)BOOL loginOrOff;

@end

@implementation Setting_ViewController
static NSString *identifier = @"identifier";

#pragma mark - 懒加载
- (UITableView *)tableview {
    
    if (_tableview == nil) {
        
        _tableview = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableview.delegate = self;
        _tableview.dataSource = self;
    }
    return _tableview;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self configure];
    [self setupUI];
    //    不显示多余的cell
    self.tableview.tableFooterView = [[UITableView alloc]init];
}

- (void)configure {
    
    [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:identifier];
    
    self.strArr = @[@"意见反馈",@"加号符号说明",@"修改密码",@"注销用户"];
}

#pragma mark - 设置UI界面
- (void)setupUI {
    
    [self.view addSubview:self.tableview];
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(SCREEN_HEIGHT);
        make.left.bottom.equalTo(self.view);
        make.width.mas_equalTo(SCREEN_WIDTH);
    }];
}

#pragma mark - tabelView的数据源代理
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell  *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.textLabel.text = self.strArr[indexPath.row];
      
    return cell;
    
}

#pragma mark - 选取点击的cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 3) {
               
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"你确定要注销吗?" preferredStyle:UIAlertControllerStyleActionSheet];
        
        UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            ;

            self.JASide_ViewController = [[JASidePanelController alloc] init];
            
            //实例化 左侧 Left_ViewController
            self.JASide_ViewController.leftPanel = [[Left_ViewController alloc] init];
            
            //实例化 右侧 Home_ViewController
            Home_ViewController * home_VC = [[Home_ViewController alloc] init];
            
            self.JASide_ViewController.centerPanel = [[Base_NavController alloc] initWithRootViewController:home_VC];
            
            [self presentViewController:self.JASide_ViewController animated:YES completion:nil];
            [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
            [SVProgressHUD setMinimumDismissTimeInterval:1.5];
            [SVProgressHUD showSuccessWithStatus:@"注销成功!挥一挥衣袖,不带走一片☁️☁️☁️🌈!"];
            //修改偏好中的布尔值为NO,表示未登录状态
            self.loginOrOff = NO;
            NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
            [defaults setBool:self.loginOrOff forKey:@"loadOrOff"];
            [defaults synchronize];
        
        }];
        UIAlertAction *alert = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        
        [alertController addAction:alertAction];
        [alertController addAction:alert];
        [self presentViewController:alertController animated:YES completion:nil];
     
    }else if (indexPath.row == 0) {
        FeedBackVC *feedBack = [[FeedBackVC alloc]init];
        [self.navigationController pushViewController:feedBack animated:YES];
        
    }else if (indexPath.row == 2) {
        ResetPasswordController *resetVc = [[ResetPasswordController alloc]init];
        resetVc.title = @"修改密码";
        [self.navigationController pushViewController:resetVc animated:YES];
        
    }
    //    点击cell取消
    [self.tableview deselectRowAtIndexPath:indexPath animated:YES];
}


@end
